package main

import (
	"net/http"
	"web08_35_tushu/controller"
)

func main() {
	//设置静态资源映射,/static/是web目录，StripPrefix是映射一个地址到/static/ web目录
	//FileServer是开启一个本地的文件服务器，里面是打开一个具体位置，可以是相对或绝对路径
	http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
	http.Handle("/pages/", http.StripPrefix("/pages/", http.FileServer(http.Dir("pages/"))))

	//设置主页路由
	http.HandleFunc("/main", controller.GetPageBooksByPrice)

	//用户登录
	http.HandleFunc("/login", controller.Login)
	//用户注册
	http.HandleFunc("/regist", controller.Regist)
	//用户注销
	http.HandleFunc("/logout", controller.Logout)
	//用户名检查
	http.HandleFunc("/checkUserName", controller.CheckUserName)
	//图书管理
	http.HandleFunc("/getBooks", controller.GetBooks)
	//去带分页的图书管理页，取代了getBooks路由
	http.HandleFunc("/getPageBooks", controller.GetPageBooks)
	//添加图书
	http.HandleFunc("/addBook", controller.AddBook)
	//删除图书
	http.HandleFunc("/deleteBook", controller.DeleteBook)
	//去图书更新页，这里面会查询一本图书信息
	http.HandleFunc("/toUpdateBookPage", controller.ToUpdateBookPage)
	//更新图书信息
	http.HandleFunc("/updateBook", controller.UpdateBook)

	//合并了添加和更新的函数，并且把book_modify和book_edit两个html模板也合并为book_edit了
	//去添加或更新页面，添加及更新图书信息，这是根据去更新页ToUpdateBookPage改的
	http.HandleFunc("/toUpdateBookPage2", controller.ToUpdateBookPage2)
	//合并了的函数
	http.HandleFunc("/updateOrAddBook", controller.UpdateOrAddBook)

	//带价格范围的图书显示页
	http.HandleFunc("/getPageBooksByPrice", controller.GetPageBooksByPrice)

	//下面的就是购物车相关的
	//添加图书到购物车
	http.HandleFunc("/addBook2Cart", controller.AddBook2Cart)
	//去往购物车页面
	http.HandleFunc("/getCartInfo", controller.GetCartInfo)
	//清空购物车
	http.HandleFunc("/deleteCart", controller.DeleteCart)
	//删除指定购物项
	http.HandleFunc("/deleteCartItem", controller.DeleteCartItem)
	//更新指定购物项
	http.HandleFunc("/updateCartItem", controller.UpdateCartItem)

	//去结账，保存订单
	http.HandleFunc("/checkout", controller.Checkout)
	//获取所有订单
	http.HandleFunc("/getOrders", controller.GetOrders)
	//获取订单详情，查出订单对应的订单项
	http.HandleFunc("/getOrderInfo", controller.GetOrderInfo)
	//获取已登录用户的订单
	http.HandleFunc("/getMyOrders", controller.GetMyOrders)
	//发货
	http.HandleFunc("/sendOrder", controller.SendOrder)
	//确认收货
	http.HandleFunc("/takeOrder", controller.TakeOrder)

	http.ListenAndServe(":8080", nil)
}
